package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysResourcePropertyOptionDAO;
import com.ourteam.system.dao.SysResourcePropertyOption;
import com.ourteam.system.dao.SysResourcePropertyOptionDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:34
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysResourcePropertyOptionDAOJdbcImpl
    extends AbstractSpringDAO implements ISysResourcePropertyOptionDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, OrderIndex, Remarks, Status, SysResourcePropertyId, ValueCode,
            ValueLable
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.OrderIndex,
            _DataObjectProperty.Remarks, _DataObjectProperty.Status,
            _DataObjectProperty.SysResourcePropertyId,
            _DataObjectProperty.ValueCode, _DataObjectProperty.ValueLable
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysResourcePropertyOption, SysResourcePropertyOptionDAOQueryBean> daoHelper;

    public AbstractSysResourcePropertyOptionDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysResourcePropertyOption, SysResourcePropertyOptionDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysResourcePropertyOption
         * @throws Exception
         */
    public boolean checkIsUnique(
        SysResourcePropertyOption aSysResourcePropertyOption)
        throws Exception {
        if (aSysResourcePropertyOption == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysResourcePropertyOption.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysResourcePropertyOption
     * @throws Exception
     */
    public void insert(SysResourcePropertyOption aSysResourcePropertyOption)
        throws Exception {
        super.doInsert(aSysResourcePropertyOption);
    }

    /**
         * Batch Insert Datas
         * @param aSysResourcePropertyOption
         * @throws Exception
         */
    public void batchInsert(
        SysResourcePropertyOption[] aSysResourcePropertyOptions)
        throws Exception {
        super.doBatchInsert(aSysResourcePropertyOptions);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysResourcePropertyOptionDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysResourcePropertyOption aSysResourcePropertyOption)
        throws Exception {
        delete(aSysResourcePropertyOption.getId());
    }

    /**
     * Update Data Selective
     * @param aSysResourcePropertyOption
     * @throws Exception
     */
    public void update(SysResourcePropertyOption aSysResourcePropertyOption)
        throws Exception {
        if (aSysResourcePropertyOption.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysResourcePropertyOption);

        SysResourcePropertyOption tempObj = findById(aSysResourcePropertyOption.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysResourcePropertyOption, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysResourcePropertyOptions[]
     * @throws Exception
     */
    public void batchUpdate(
        SysResourcePropertyOption[] aSysResourcePropertyOptions)
        throws Exception {
        super.doBatchUpdate(aSysResourcePropertyOptions);
    }

    /**
         * Update Data By Condictions
         * @param aSysResourcePropertyOption
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysResourcePropertyOption aSysResourcePropertyOption,
        SysResourcePropertyOptionDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aSysResourcePropertyOption, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysResourcePropertyOptionDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(
        SysResourcePropertyOption aSysResourcePropertyOption)
        throws Exception {
        if (aSysResourcePropertyOption.getOrderIndex() == null) {
            throw new Exception(
                "The SysResourcePropertyOption.orderIndex value is not allow NULL");
        }

        if (aSysResourcePropertyOption.getRemarks() == null) {
            throw new Exception(
                "The SysResourcePropertyOption.remarks value is not allow NULL");
        }

        if (aSysResourcePropertyOption.getStatus() == null) {
            throw new Exception(
                "The SysResourcePropertyOption.status value is not allow NULL");
        }

        if (aSysResourcePropertyOption.getSysResourcePropertyId() == null) {
            throw new Exception(
                "The SysResourcePropertyOption.sysResourcePropertyId value is not allow NULL");
        }

        if (aSysResourcePropertyOption.getValueCode() == null) {
            throw new Exception(
                "The SysResourcePropertyOption.valueCode value is not allow NULL");
        }

        if (aSysResourcePropertyOption.getValueLable() == null) {
            throw new Exception(
                "The SysResourcePropertyOption.valueLable value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysResourcePropertyOption findById(final long id)
        throws Exception {
        SysResourcePropertyOptionDAOQueryBean queryBean = new SysResourcePropertyOptionDAOQueryBean();

        SysResourcePropertyOptionDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysResourcePropertyOption[] SysResourcePropertyOptions = query(queryBean);

        if (SysResourcePropertyOptions.length == 0) {
            return null;
        } else {
            return SysResourcePropertyOptions[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysResourcePropertyOption[]
         * @throws Exception
         */
    public SysResourcePropertyOption[] query(
        SysResourcePropertyOptionDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcSysResourcePropertyOptionRowMapper());

        return (SysResourcePropertyOption[]) result.toArray(new SysResourcePropertyOption[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysResourcePropertyOptionDAOQueryBean queryBean)
        throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysResourcePropertyOptionDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(
        SysResourcePropertyOption[] aSysResourcePropertyOptions,
        SysResourcePropertyOptionDAOQueryBean queryBean)
        throws Exception {
        daoHelper.synchronize(aSysResourcePropertyOptions, queryBean);
    }

    public void synchronize(
        SysResourcePropertyOption[] aSysResourcePropertyOptions,
        SysResourcePropertyOptionDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysResourcePropertyOption> callBack)
        throws Exception {
        daoHelper.synchronize(aSysResourcePropertyOptions, queryBean, callBack);
    }

    public static class JdbcSysResourcePropertyOptionRowMapper
        implements RowMapper<SysResourcePropertyOption> {
        public SysResourcePropertyOption mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysResourcePropertyOption object = new SysResourcePropertyOption();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object orderIndex = null;

                orderIndex = resultSet.getObject(columnIndex++);

                object.setOrderIndexNull(resultSet.getBoolean(columnIndex++));

                if (orderIndex != null) {
                    setBeanValue(object, _DataObjectProperty.OrderIndex,
                        orderIndex);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object sysResourcePropertyId = null;

                sysResourcePropertyId = resultSet.getObject(columnIndex++);

                object.setSysResourcePropertyIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysResourcePropertyId != null) {
                    setBeanValue(object,
                        _DataObjectProperty.SysResourcePropertyId,
                        sysResourcePropertyId);
                }

                Object valueCode = null;

                valueCode = resultSet.getObject(columnIndex++);

                object.setValueCodeNull(resultSet.getBoolean(columnIndex++));

                if (valueCode != null) {
                    setBeanValue(object, _DataObjectProperty.ValueCode,
                        valueCode);
                }

                Object valueLable = null;

                valueLable = resultSet.getObject(columnIndex++);

                object.setValueLableNull(resultSet.getBoolean(columnIndex++));

                if (valueLable != null) {
                    setBeanValue(object, _DataObjectProperty.ValueLable,
                        valueLable);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
